﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Air_condition.DO
{
    [Serializable]
    public class Glass
    {
        // Attributes of glass object
        private string sname;
        //Emm
        private double dbeffectCoefficient;
        //Em
        private double dbglassCoefficient;
        //nt
        private double dbimmediateCoefficient;
        //Rmax
        private double dbsolarRadition;
        private double dbarea;
        private int iwindowFrameType = -1;
        private int itypeofglass = -1;
        private int ilatitute = -1;
        private int imonth = -1;
        private int ipressure = -1;
        private int itime = -1;
        private int idirection = -1;
        private int isolarHour = -1;

        // Public access to attributes
        public int iSolarHour
        {
            get { return isolarHour; }
            set { isolarHour = value; }
        }

        public int iDirection
        {
            get { return idirection; }
            set { idirection = value; }
        }

        public int iTime
        {
            get { return itime; }
            set { itime = value; }
        }

        public int iPressure
        {
            get { return ipressure; }
            set { ipressure = value; }
        }

        public int iMonth
        {
            get { return imonth; }
            set { imonth = value; }
        }

        public int iLatitute
        {
            get { return ilatitute; }
            set { ilatitute = value; }
        }

        public int iTypeofglass
        {
            get { return itypeofglass; }
            set { itypeofglass = value; }
        }

        public string sName
        {
            get { return sname; }
            set { sname = value; }
        }

        public double dbGlassCoefficient
        {
            get { return dbglassCoefficient; }
            set { dbglassCoefficient = value; }

        }

        public double dbImmediateCoefficient
        {
            get { return dbimmediateCoefficient; }
            set { dbimmediateCoefficient = value; }

        }

        public double dbSolarRadition
        {
            get { return dbsolarRadition; }
            set { dbsolarRadition = value; }
        }

        public int iWindowFrameType
        {
            get { return iwindowFrameType; }
            set { iwindowFrameType = value; }
        }

        public double dbArea
        {
            get { return dbarea; }
            set { dbarea = value; }
        }

        //  Tính nhiệt bức xạ qua kính Q11
        /// <summary>
        /// Method to calculate the radiation heat through glass (Q11)
        /// </summary>
        /// <returns>the radiation heat through glass (double number)</returns>
        public double CalculateGlassRadiationHeat()
        {
            double dbglassArea = 0;
            // If frame is wood
            if (iwindowFrameType == 0)
            {
                dbglassArea = 0.85 * dbarea;
                dbeffectCoefficient = 1;
            }
            else
            {
                // If frame is metal
                dbglassArea = dbarea;
                dbeffectCoefficient = 1.17;
            }
            return dbimmediateCoefficient * dbglassArea * dbsolarRadition * dbeffectCoefficient * dbglassCoefficient;
        }

        /// <summary>
        /// method to copy Room object to a new object
        /// </summary>
        /// <returns>a new object is Room object type</returns>
        public object Clone()
        {
            object clone;
            try
            {
                using (MemoryStream stream = new MemoryStream())
                {

                    BinaryFormatter formatter = new BinaryFormatter();

                    // Serialize this object

                    formatter.Serialize(stream, this);

                    stream.Position = 0;

                    // Deserialize to another object

                    clone = formatter.Deserialize(stream);

                }
                return clone;
            }
            catch (Exception e)
            {
                return e;
            }
        }

    }
}
